<?php
defined('DCS_ROOT') or exit(header("HTTP/1.1 430 Not Forbidden"));

class ajax {

	function __construct (){
		$this->url = getUrl();
		//de($this->url);		
		$action = $this->url['params']['1'];
		if($action == 'mainreview'){
			$this->mainReview();
		}elseif($action == 'maincomment'){
			$this->mainComment();
		}else{
			$this->defaultAction();
		}
		exit();
	}
	
	function defaultAction(){
		exit();
	}

	function mainComment(){
		$db  = getDB();
		$pagetemp = $this->url['params']['2'];

		$param['table'] = ' movie_comments AS c,member AS m,movie AS m2  ';
		$param['field'] = ' c.id,c.uid,c.mid,c.rating,c.contents,m.username,m.avatars,m2.id,m2.title mtitle  ';
		$param['where'] = "  c.uid = m.uid AND c.mid = m2.id ";
		$param['order'] = ' c.addtime DESC';
		$param['page'] = is_numeric($pagetemp) ? $pagetemp :'1';		
		$param['rows'] = '4';
		$comments = $db->getList($param);
		if(!empty($comments)){
			foreach($comments as $k=>$v){
				$v['addtime'] = date('m月d日',$v['addtime']);

				echo '<div class="ctsh" style="float:left;margin-bottom:10px;border-bottom:1px #ccc dashed;padding-bottom:10px">
					<div style="float:left;width:55px;"><a href="/people/'.$v['uid'].'/"><img class="pil" src="'.PUB.'avatars/'.$v['avatars'].'"/></a></div>
					<div style="float:right;;width:535px;">
					<a href="/people/'.$v['uid'].'/">'.$v['username'].'</a>&nbsp;<span style="color:#999">评论</span>&nbsp;<a href="/movie/'.$v['mid'].'/">'.$v['mtitle'].'</a>：
					'.html2Txt($v['contents']).'
					</div>	
				</div>
				<div class="clear"></div>
				';
			}
			$prev = $param['page'] - 1;
			$prev = $prev < 1 ? 1 : $prev;
			$next = $param['page'] + 1;


			echo '<p class="pl" align="right">
			<a href="javascript:;" onclick="cPrevNext('.$prev.');" class="prev1" >上一页</a>&nbsp;|&nbsp;
			<a href="javascript:;" onclick="cPrevNext('.$next.');" class="next1">下一页</a></p>';
		}else{
			echo 'empty';
		}
		
	}

	function mainReview(){
		$db  = getDB();
		$pagetemp = $this->url['params']['2'];
		$param['table'] = ' movie_review AS r,member AS m,movie AS m2  ';
		$param['field'] = ' r.id,r.uid,r.mid,r.rating,r.title,r.contents,r.reply,r.addtime,m.username,m.avatars,m2.title mtitle   ';
		$param['where'] = " r.uid = m.uid AND r.mid = m2.id ";
		$param['order'] = ' r.addtime DESC';
		$param['page'] = is_numeric($pagetemp) ? $pagetemp :'1';		
		$param['rows'] = '4';
		$comments = $db->getList($param);
		if(!empty($comments)){
			foreach($comments as $k=>$v){
				$v['addtime'] = date('m月d日',$v['addtime']);
				$v['contents'] = csubstr(html2Txt($v['contents']),120);

				echo '
<div class="ctsh">
<ul class="tlst clearfix" style="clear:both">
	<li class="nlst"><h3><a href="/review/'.$v['id'].'/">'.$v['title'].'</a><div class="rr"><a href="/review/'.$v['id'].'/"><img src="'.PUB.'img/arrow2.gif"/></a></div></h3>
	</li>
	<li class="ilst" style="clear:both;"><a href="/people/'.$v['uid'].'/"><img class="pil" src="'.PUB.'avatars/'.$v['avatars'].'"/></a></li>
	<li class="clst">
		<span class="pl ll obss"><span class="starb">
		<a href="/people/'.$v['uid'].'/">'.$v['username'].'</a>&nbsp;</span>评论 <a href="/movie/'.$v['mid'].'/">'.$v['mtitle'].'</a><span class="stars'.$v['rating'].' stars"></span></span><br/><br/>
		<div>'.$v['contents'].'...... 
		<a class="pl" href="/review/'.$v['id'].'/">('.$v['reply'].'回应)</a><br/>
		<div class="pl clearfix"><span class="fleft">'.$v['addtime'].' &nbsp; &nbsp;</span></div></div>
	</li>
</ul>
</div>
<div class="clear"></div>
';
			}
			$prev = $param['page'] - 1;
			$prev = $prev < 1 ? 1 : $prev;
			$next = $param['page'] + 1;
			echo '<p class="pl" align="right">
			<a href="javascript:;" onclick="rPrevNext('.$prev.');" class="prev1" >上一页</a>&nbsp;|&nbsp;
			<a href="javascript:;" onclick="rPrevNext('.$next.');" class="next1">下一页</a></p>';
		}else{
			echo 'empty';
		}
		
	}
}

?>
